package com.issac.springbootredis.jedispool;

import com.issac.springbootredis.jedispool.CallWithJedis;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

public class Redis {
    private JedisPool pool;
    public Redis() {
        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
        //空闲时检查有效性
        config.setTestOnBorrow(true);
        //最大连接数
        config.setMaxTotal(1000);
        //最大空闲数
        config.setMaxIdle(200);
        //最大等待时间
        config.setMaxWaitMillis(30000);
        pool = new JedisPool(config,"192.168.29.130",6379,30000,"issac");
    }
    public void exectue(CallWithJedis callWithJedis){
        try (Jedis jedis = pool.getResource()) {
            callWithJedis.call(jedis);
        }
    }

}
